package com.wecommodule.bpm.ext.framework.common.entity;

import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 公共结果响应
 *
 */
@Data
@ToString
@Slf4j
public class BpmResponseResult<T> implements Serializable {
    private static final long serialVersionUID = 1921092745L;

    private String errmsg;

    private Integer errcode;

    private T data;

    public BpmResponseResult(String message, Integer code, T data) {
        this.errmsg = message;
        this.errcode = code;
        this.data = data;
    }


    public static <T> BpmResponseResult<T> successResponse(String message, T data){
        return new BpmResponseResult<>(message,HttpStatus.OK.value(),data);
    }

    public static <T> BpmResponseResult<T> successResponse(String message){
        return new BpmResponseResult<>(message,HttpStatus.OK.value(),null);
    }

    public static <T> BpmResponseResult<T> successResponse(String message, Integer code, T data){
        return new BpmResponseResult<>(message,code,data);
    }


    public static <T> BpmResponseResult<T> errorResponse(String message, T data){
        return new BpmResponseResult<>(message,HttpStatus.INTERNAL_SERVER_ERROR.value(),data);
    }

    /**
     * 响应自定义错误消息
     * 响应状态码：500
     * @param message
     * @return
     */
    public static <T> BpmResponseResult<T> errorResponse(String message){
        return new BpmResponseResult<>(message,HttpStatus.INTERNAL_SERVER_ERROR.value(),null);
    }


    /**
     * 响应自定义错误消息，自定义响应状态码
     * @param message  错误响应信息
     * @param code 自定义响应状态码
     * @return
     */
    public static <T> BpmResponseResult<T> errorResponse(String message, Integer code){
        return new BpmResponseResult<>(message,code,null);
    }

}
